package com.asseco.mio.codex.controllers;

///*
// * To change this template, choose Tools | Templates
// * and open the template in the editor.
// */
//package com.asseco.mio.codex.controllers;
//
//import com.asseco.mio.BasicInfo;
//import com.asseco.mio.WorkPosition;
//import com.asseco.mio.codex.EmploymentReason;
//import com.asseco.mio.codex.LeaveReason;
//import com.asseco.persistence.service.HibernateUtil;
//import java.util.ArrayList;
//import java.util.List;
//import org.appfuse.service.GenericManager;
//import org.appfuse.service.UserManager;
//import org.hibernate.Query;
//import org.hibernate.Session;
//import org.hibernate.criterion.Restrictions;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//
///**
// *
// * @author konstantin.sivakov
// */
//@Controller
//@RequestMapping("/workpositionsearch*")
//public class WorkPositionSearchController {
//
//    private GenericManager<BasicInfo, String> basicInfoManager;
//    private GenericManager<LeaveReason, String> leaveReasonManager;
//    private GenericManager<EmploymentReason, String> emplReasonManager;
//    @Autowired
//    UserManager userManager;
//
//    @Autowired
//    public void setBasicInfoManager(@Qualifier("basicInfoManager") GenericManager<BasicInfo, String> basicInfoManager) {
//        this.basicInfoManager = basicInfoManager;
//    }
//
//    @Autowired
//    public void setLeaveReasonManager(@Qualifier("leaveReasonManager") GenericManager<LeaveReason, String> leaveReasonManager) {
//        this.leaveReasonManager = leaveReasonManager;
//    }
//
//    @Autowired
//    public void setEmplReasonManager(@Qualifier("emplReasonManager") GenericManager<EmploymentReason, String> emplReasonManager) {
//        this.emplReasonManager = emplReasonManager;
//    }
//
//    public List getWorkPosition(WorkPosition workPosition) {
//
//        String pamFirstName = "%";
//        String pamLastName = "%";
//        String pamSocScrNo = "%";
//        String pamEmplReason = "%";
//        String pamLeaveReason = "%";
//        String pamPositon = "%";
//
//
//        Session session = HibernateUtil.getSessionFactory().openSession();
//        session.beginTransaction();
//        if (workPosition.getEmployment() == null) {
//            workPosition.setEmployment(new BasicInfo());
//        }
//
//
//        if (workPosition.getEmployment().getFirstName() != null) {
//            if (!workPosition.getEmployment().getFirstName().equals("")) {
//                pamFirstName = "%" + workPosition.getEmployment().getFirstName() + "%";
//            }
//        }
//        if (workPosition.getEmployment().getLastName() != null) {
//            if (!workPosition.getEmployment().getLastName().equals("")) {
//                pamLastName = "%" + workPosition.getEmployment().getLastName() + "%";
//            }
//        }
//        if (workPosition.getEmployment().getSocScrNo() != null) {
//            if (!workPosition.getEmployment().getSocScrNo().equals("")) {
//                pamSocScrNo = "%" + workPosition.getEmployment().getSocScrNo() + "%";
//            }
//        }
//        if (workPosition.getEmplReason() != null) {
//            if (workPosition.getEmplReason().getId().equals("")) {
//                EmploymentReason er = emplReasonManager.get(workPosition.getEmplReason().getId());
//                workPosition.setEmplReason(er);
//                pamEmplReason = "%" + workPosition.getEmplReason().getName() + "%";
//            }
//        }
//        if (workPosition.getLeaveReason() != null) {
//            if (workPosition.getLeaveReason().getId().equals("")) {
//                LeaveReason lr = leaveReasonManager.get(workPosition.getLeaveReason().getId());
//                workPosition.setLeaveReason(lr);
//                pamLeaveReason = "%" + workPosition.getLeaveReason().getName() + "%";
//            }
//        }
//
//        Query q = session.createQuery("from WorkPosition workPos inner join workPos.employment where workPos.position != 'null' "
//                + "and workPos.emplReason.name like '" + pamEmplReason + "'"
//                + "and workPos.leaveReason.name like '" + pamLeaveReason + "'"
//                + "and workPos.position="+pamPositon+"and workPos.status!='null' "
//                + "and ( "
//                + "workPos.employment.firstName like '" + pamFirstName + "' and "
//                + "workPos.employment.lastName like '" + pamLastName + "' and "
//                + "workPos.employment.socScrNo like '" + pamSocScrNo + "') order by workPos.employment,workPos.startDate");
//
//
//        List tempResult = q.list();
//        List result = new ArrayList();
//        for (int j = 0; j < tempResult.size(); j++) {
//            WorkPosition object = (WorkPosition) tempResult.get(j);
//            result.add(object);
//        }
//        session.getTransaction().commit();
//        return result;
//
//    }
//}
